package cn.openea.perpartner.componet.web.controller;

import cn.hutool.core.util.StrUtil;
import cn.openea.perpartner.common.core.web.controller.BaseController;
import cn.openea.perpartner.common.core.web.domain.AjaxResult;
import cn.openea.perpartner.componet.annotation.ChainLog;
import cn.openea.perpartner.componet.web.entity.dto.InviteDto;
import cn.openea.perpartner.componet.web.entity.dto.ShareDto;
import cn.openea.perpartner.componet.web.service.IShareService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @author Weird077
 * @description TODO
 * @date 2023-03-01 13:27
 */
@Api(tags = "分享管理")
@RestController
@RequestMapping("/share")
public class ShareController extends BaseController {
    @Resource
    private IShareService shareService;

    @ApiOperation(value = "链接分享")
    @PostMapping("/link")
    public AjaxResult linkShare(@RequestBody ShareDto shareDto){
        String url = shareService.linkShare(shareDto);
        return StrUtil.isBlank(url)?AjaxResult.error("分享失败！"):AjaxResult.success("分享成功！",url);
    }
    @ApiOperation(value = "菊花码分享")
    @PostMapping("/qrcode")
    public AjaxResult codeShare(@RequestBody ShareDto shareDto) throws IOException {
        String url = shareService.codeShare(shareDto);
        return StrUtil.isBlank(url)?AjaxResult.error("生成菊花码失败！"):AjaxResult.success("生成菊花码成功！",url);
    }
    @ApiOperation(value = "海报分享")
    @PostMapping("/posters")
    public AjaxResult postersShare(@RequestBody ShareDto shareDto) throws IOException {
        String url = shareService.postersShare(shareDto);
        return StrUtil.isBlank(url)?AjaxResult.error("生成海报失败！"):AjaxResult.success("生成海报成功！",url);
    }

    @ChainLog
    @ApiOperation(value = "获取转向地址")
    @PostMapping("/getPage")
    public AjaxResult findById(@RequestBody InviteDto inviteDto)  {
        String url = shareService.findById(inviteDto.getShareId());
        return StrUtil.isBlank(url)?AjaxResult.error("获取转向地址失败！"):AjaxResult.success("获取转向地址成功！",url);
    }
}
